package Year21_Month12.day1202;

public class Soultion {
    public int removeDuplicates(int[] nums) {
        if(nums.length < 3){
            return nums.length;
        }
        int pre = 2;
        int count = 0;
        for(int i = 2;i < nums.length;i++){
            if(nums[i] != nums[pre - 2]){
                nums[pre] = nums[i];
                pre++;
                count++;
            }
        }
        return nums.length - count;
    }

    public int maxProfit(int[] prices) {
        int minprice = prices[0];
        int max = 0;
        for(int i = 0;i < prices.length;i++){
            if(prices[i] < minprice){
                minprice = prices[i];
            }else if(prices[i] - minprice > max){
                max = prices[i] - minprice;
            }
        }
        return max;
    }
}
